package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Suanfaleibie;
import com.example.exception.CustomException;
import com.example.service.SuanfaleibieService;
import com.example.vo.SuanfaleibieVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("suanfaleibieService")
public class SuanfaleibieServiceImpl extends ServiceImpl<SuanfaleibieDao, Suanfaleibie> implements SuanfaleibieService {

    @Resource
    private SuanfaleibieDao suanfaleibieDao;

    public Suanfaleibie add(Suanfaleibie suanfaleibie) {
		
	   //youquchong1
        suanfaleibie.setAddtime(new Date());
        suanfaleibieDao.insert(suanfaleibie);
        return suanfaleibie;
    }
	
	
	
    public void delete(Long id) {
        suanfaleibieDao.deleteById(id);
    }
	

    public void update(Suanfaleibie suanfaleibie) {
        //youquchong2
        suanfaleibieDao.updateById(suanfaleibie);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return suanfaleibieDao.daochuexcel();
    }

    @Override
    public Suanfaleibie findById(Integer id) {
        return suanfaleibieDao.selectById(id);
    }

    public SuanfaleibieVo findPage(SuanfaleibieVo suanfaleibieVo) {
        LambdaQueryWrapper<Suanfaleibie> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(suanfaleibieVo.getSuanfajingsai()), Suanfaleibie::getSuanfajingsai,suanfaleibieVo.getSuanfajingsai());        
        Page<Suanfaleibie> page = new Page<>(suanfaleibieVo.getCurrent(),suanfaleibieVo.getCurrentNum());
        suanfaleibieDao.selectPage(page,wrapper);
        List<Suanfaleibie> suanfaleibies = page.getRecords();
        suanfaleibieVo.setList(suanfaleibies);
        suanfaleibieVo.setPages(page.getPages());
        suanfaleibieVo.setTotal(page.getTotal());
        suanfaleibieVo.setCurrent(page.getCurrent());
        suanfaleibieVo.setCurrentNum(page.getSize());
        return suanfaleibieVo;
    }

    @Override
    public void deleteList(List<Suanfaleibie> list) {
        List<Integer> ids =  list.stream().map(Suanfaleibie::getId).collect(Collectors.toList());
        suanfaleibieDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
